﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using System.Text;

using Gift.DAL;
using Gift.Model;

namespace WebSite.cn
{
    public partial class bottom : System.Web.UI.UserControl
    {
        BasePage theBase = new BasePage();
        readonly DALCar theCar = new DALCar();
        readonly MemberAccount theMemberAccount = new MemberAccount();
        public string linkstr = "";

        public StringBuilder sbFooterHtml = new StringBuilder(); 

        // Methods
        protected void Page_Load(object sender, EventArgs e)
        {


                this.BindBottomMenu();
        
            }

        void BindBottomMenu()
        {
            string str2 = "select navigatorId,navigatorLink,navigatorName from tbNavigator where parentid=0 and visible=1 and navigatorName<>''   order by navigatorOrder";
            DataTable table2 = SQLAccess.GreatDs(str2).Tables[0];

            DataTable tableSub;

            foreach (DataRow dr in table2.Rows)
            {
                sbFooterHtml.AppendFormat("<dl class=\"dt_con\"><dt>{0}</dt>"
                                           , dr["navigatorName"].ToString()
                                           );
                tableSub = SQLAccess.GreatDs(string.Format("select navigatorId,navigatorLink,navigatorName from tbNavigator where parentid={0} and visible=1 and navigatorName<>''    order by navigatorOrder", dr["navigatorId"].ToString())).Tables[0];
                if (tableSub != null && tableSub.Rows.Count > 0)
                {
                    foreach (DataRow drSub in tableSub.Rows)
                    {
                        sbFooterHtml.AppendFormat("<dd><a href=\"{0}\" target='_blank'>{1}</a></dd>"
                            , drSub["navigatorLink"].ToString() == "" ? "/cn/content.aspx?cid=" + drSub["navigatorId"].ToString() : drSub["navigatorLink"].ToString()
                                                   , drSub["navigatorName"].ToString()
                                                   );

                    }
                }
                sbFooterHtml.Append("</dl>");
            }
        }

        void BindLink()
        {
            //string sql = "select * from DB_Link where visible=1 and languages=1 order by linkorder";
            //DataTable table = SQLAccess.GreatDs(sql).Tables[0];
            //if (table.Rows.Count > 0)
            //{
            //    foreach (DataRow row in table.Rows)
            //    {
            //        if (row["linkfile"].ToString() != "")
            //        {
            //            string linkstr = this.linkstr;
            //            this.linkstr = linkstr + "<a href='" + row["linkurl"].ToString() + "' target='_blank'><img src='/uploadfile/link/" + row["linkfile"].ToString() + "' border='0' /></a>  ";
            //        }
            //        else
            //        {
            //            string str4 = this.linkstr;
            //            this.linkstr = str4 + "<a href='" + row["linkurl"].ToString() + "' target='_blank'>" + row["linkname"].ToString() + "</a>  ";
            //        }
            //    }
            //}
            
        }


        public string GetAccountCount()
        {
            DataTable table = new DataTable();
            if (theBase.LoginUserMember != null && theBase.LoginUserMember.TempMembertId != "")
            {
                if (theBase.LoginUserMember.IsCard)
                {
                    table = theCar.GetListByMemberId(long.Parse(theBase.LoginUserMember.TempMembertId), 1).Tables[0];
                }
            }
            else
            {
                if (re.ReadCookie("tempnoCard") != null)
                {
                    try
                    {
                        table = theCar.GetListByMemberId(long.Parse(re.ReadCookie("tempnoCard")), 1).Tables[0];
                    }
                    catch
                    {
                    }
                }
            }

            DataTable tbCardGoods = new DataTable();
            if (theBase.LoginUserMember != null && theBase.LoginUserMember.MemberId != "")
            {
                tbCardGoods = theCar.GetListByMemberId(long.Parse(theBase.LoginUserMember.MemberId), 0).Tables[0];
            }
            else
            {
                if (re.ReadCookie("tempnoGenerate") != null)
                {
                    try
                    {
                        tbCardGoods = theCar.GetListByMemberId(long.Parse(re.ReadCookie("tempnoGenerate")), 0).Tables[0];
                    }
                    catch
                    {
                    }
                }
            }
            int iCarCount = 0;
            if (table != null)
            {
                iCarCount = table.Rows.Count;
            }
            if (tbCardGoods != null)
            {
                iCarCount = iCarCount + tbCardGoods.Rows.Count;
            }
            return iCarCount.ToString();
        }

        public string GetAccountMoney()
        {

            if (theBase.LoginUserMember == null || string.IsNullOrEmpty(theBase.LoginUserMember.MemberId))
            {
                return "";
            }
            else
            {
                return string.Format("{0}"
                                      , theMemberAccount.GetRemainSumMoney(int.Parse(theBase.LoginUserMember.MemberId)).ToString()
                                      );

            }
        }



    }
}